package com.foo.cms.service.impl;

import com.foo.cms.service.BaseService;
import com.foo.cms.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: LZS
 * Date: 12-6-24
 * Time: 下午4:12
 * To change this template use File | Settings | File Templates.
 */
@Service
public class CategoryServiceImpl extends BaseService implements CategoryService {
    @Override
    public Map<Object,Object> listAll() {
        Map<Object,Object> result = new HashMap<Object, Object>();
        String sql = "select * from dt_category where vc2enableflag='Y'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql, new HashMap<String, Object>());
        for(Map<String,Object> map : list){
            result.put(map.get("numcategoryid"),map.get("vc2categoryname"));
        }
        return result;  //To change body of implemented methods use File | Settings | File Templates.
    }



    @Override
    public Map<Object, Object> listByArticleId(String id) {
        Map<Object, Object> categoryMap = new HashMap<Object, Object>();
        Map<String,Object> params = new HashMap<String, Object>();
        params.put("id",id);
        String sql = "select a.numarticleid,a.numcategoryid from DT_ARTICLE_CATEGORY a inner join dt_article b on a.numarticleid=b.numarticleid where b.numarticleid=:id";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql,params);
        for (Map<String, Object> map : list) {
            categoryMap.put(map.get("numcategoryid"), map.get("numarticleid"));
        }
        return categoryMap;
    }
}
